<template>
  <div class="m-leadTabFrom m-dialog">
    <el-form :model="form.data" :inline="true" label-width="140px" label-position="left">
      <div>
        <el-form-item label="广告来源">
          <el-input v-model="form.data.adSource" disabled></el-input>
        </el-form-item>
      </div>
      <div>
        <el-form-item label="广告媒介">
          <el-input v-model="form.data.adMedium" disabled></el-input>
        </el-form-item>
      </div>
      <div>
        <el-form-item label="广告系列">
          <el-input v-model="form.data.adSerial" disabled></el-input>
        </el-form-item>
      </div>
      <div>
        <el-form-item label="渠道来源">
          <el-input v-model="form.data.chlSource" :clearable="isEdit" :disabled="!isEdit"></el-input>
        </el-form-item>
      </div>
      <div>
        <el-form-item label="意向度">
          <el-select clearable v-model="form.data.degree" placeholder="请选择" :clearable="isEdit" :disabled="!isEdit">
            <el-option label="高" value="高"></el-option>
            <el-option label="中" value="中"></el-option>
            <el-option label="低" value="低"></el-option>
            <el-option label="无" value="无"></el-option>
          </el-select>
        </el-form-item>
      </div>
      <div>
        <el-form-item label="投资经验">
          <el-select clearable v-model="form.data.exp" placeholder="请选择" :clearable="isEdit" :disabled="!isEdit">
            <el-option label="无" value="无"></el-option>
            <el-option label="少于6个月" value="少于6个月"></el-option>
            <el-option label="1年以上" value="1年以上"></el-option>
            <el-option label="5年以上" value="5年以上"></el-option>
          </el-select>
        </el-form-item>
      </div>
      <div>
        <el-form-item label="曾接触的投资产品">
          <el-select clearable v-model="form.data.ever" placeholder="请选择" :clearable="isEdit" :disabled="!isEdit"
                     multiple>
            <el-option label="外汇" value="外汇"></el-option>
            <el-option label="贵金属" value="贵金属"></el-option>
            <el-option label="能源" value="能源"></el-option>
            <el-option label="指数" value="指数"></el-option>
            <el-option label="商品" value="商品"></el-option>
            <el-option label="数字货币" value="数字货币"></el-option>
            <el-option label="证券" value="证券"></el-option>
            <el-option label="期货" value="期货"></el-option>
            <el-option label="期权" value="期权"></el-option>
          </el-select>
        </el-form-item>
      </div>
      <div>
        <el-form-item label="CS获取LEAD途径">
          <el-select clearable v-model="form.data.root" placeholder="请选择" :clearable="isEdit" :disabled="!isEdit">
            <el-option label="Live800" value="Live800"></el-option>
            <el-option label="QQ" value="QQ"></el-option>
            <el-option label="WeChat" value="WeChat"></el-option>
            <el-option label="客服电话" value="客服电话"></el-option>
          </el-select>
        </el-form-item>
      </div>
      <div>
        <el-form-item label="CS获取LEAD时间">
          <el-date-picker
            v-model="form.data.rootTime"
            type="datetime"
            :editable="false"
            format="yyyy-MM-dd HH:mm:ss"
            value-format="yyyy-MM-dd HH:mm:ss"
            :disabled="!isEdit"
            clearable
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
      </div>
      <div class="flex row-towItem">
        <div>
          <el-form-item label="短信推送次数">
            <el-input v-model="form.data.pushSMS" :clearable="isEdit" :disabled="!isEdit"></el-input>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="邮件推送次数">
            <el-input v-model="form.data.pushEmail" :clearable="isEdit" :disabled="!isEdit"></el-input>
          </el-form-item>
        </div>
      </div>
      <div class="flex row-towItem">
        <div>
          <el-form-item label="QQ推送次数">
            <el-input v-model="form.data.pushQQ" :clearable="isEdit" :disabled="!isEdit"></el-input>
          </el-form-item>
        </div>
        <div></div>
      </div>
      <div class="activeBtns" v-if="isEdit">
        <el-button plain>取消</el-button>
        <el-button type="primary" @click="submit" :loading="addLoading">更新</el-button>
      </div>
    </el-form>
  </div>
</template>

<script>
  import * as LeadsAPI from '@/Api/lead';
  import * as Utils from '@/utils'
  export default {
    name: 'TheLeadCommonRe',
    data () {
      return {
        form: {
          data: {},
        },
        copyForm: null,
        addLoading:false,
      }
    },
    computed: {
      isEdit(){
        if (this.$route.query.type && this.$route.query.type == 'edit') {
          return true;
        } else {
          return false;
        }
      }
    },
    methods: {
      submit() {
        /*
         * query.type  edit编辑模式
         * query.from  desktop 来自我的桌面
         * query.group  a 分配给我的  b 我关注的
         *
         * */
        let ajaxAddress = null;
        this.addLoading = true;
        if(this.$route.query.from == 'desktop') {
          if(this.$route.query.group == 'a') {
            ajaxAddress =  LeadsAPI.ialeadRefEdit;
          } else  {
            ajaxAddress =  LeadsAPI.ifleadRefEdit;
          }
        } else {
          ajaxAddress =  LeadsAPI.leadRefEdit;
        }

        ajaxAddress(Object.assign(Utils.updateFormItemCopy(this.copyForm), this.form.data, {
          ever: this.form.data.ever.join('|'),
          id: this.$route.params.id.split("_")[0]
        }))
          .then(res => {
            this.addLoading = false;
            if (res.code != 0) {
              this.$notify.warning({
                title: '温馨提示',
                message: res.msg
              })
              return;
            }
            this.$message({
              type: 'success',
              message: '修改成功!'
            });
            this.queryInfo();
          })
          .catch(error => {
            this.addLoading = false;
            console.log(error)
          })
      },
      queryInfo(){
        LeadsAPI.leadLeadRe({
          id: this.$route.params.id.split("_")[0],
//          phone: _arr[1],
        })
          .then(res => {
            if (res.code != 0) {
              this.$notify.warning({
                title: '温馨提示',
                message: res.msg
              })
              return;
            }
            this.copyForm = Object.assign({}, res.data ? res.data : {});
            this.form.data = Object.assign({
              ever: ''
            }, res.data);
            this.form.data.ever = this.form.data.ever ? this.form.data.ever.split('|') : [];

          })
          .catch(error => {
            console.log(error)
          })
      }
    },
    created(){
      this.queryInfo()
    }
  }
</script>

<style scoped lang="scss"></style>
